package com.ruoyi.bom.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bom.domain.ErpComponentBom;
import com.ruoyi.bom.service.IErpComponentBomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 子件BOMController
 * 
 * @author ruoyi
 * @date 2025-07-24
 */
@RestController
@RequestMapping("/bom/erp_component_bom")
public class ErpComponentBomController extends BaseController
{
    @Autowired
    private IErpComponentBomService erpComponentBomService;

    /**
     * 查询子件BOM列表
     */
    @PreAuthorize("@ss.hasPermi('bom:erp_component_bom:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpComponentBom erpComponentBom)
    {
        startPage();
        List<ErpComponentBom> list = erpComponentBomService.selectErpComponentBomList(erpComponentBom);
        return getDataTable(list);
    }

    /**
     * 导出子件BOM列表
     */
    @PreAuthorize("@ss.hasPermi('bom:erp_component_bom:export')")
    @Log(title = "子件BOM", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpComponentBom erpComponentBom)
    {
        List<ErpComponentBom> list = erpComponentBomService.selectErpComponentBomList(erpComponentBom);
        ExcelUtil<ErpComponentBom> util = new ExcelUtil<ErpComponentBom>(ErpComponentBom.class);
        util.exportExcel(response, list, "子件BOM数据");
    }

    /**
     * 获取子件BOM详细信息
     */
    @PreAuthorize("@ss.hasPermi('bom:erp_component_bom:query')")
    @GetMapping(value = "/{componentId}")
    public AjaxResult getInfo(@PathVariable("componentId") String componentId)
    {
        return success(erpComponentBomService.selectErpComponentBomByComponentId(componentId));
    }

    /**
     * 新增子件BOM
     */
    @PreAuthorize("@ss.hasPermi('bom:erp_component_bom:add')")
    @Log(title = "子件BOM", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpComponentBom erpComponentBom)
    {
        return toAjax(erpComponentBomService.insertErpComponentBom(erpComponentBom));
    }

    /**
     * 修改子件BOM
     */
    @PreAuthorize("@ss.hasPermi('bom:erp_component_bom:edit')")
    @Log(title = "子件BOM", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpComponentBom erpComponentBom)
    {
        return toAjax(erpComponentBomService.updateErpComponentBom(erpComponentBom));
    }

    /**
     * 删除子件BOM
     */
    @PreAuthorize("@ss.hasPermi('bom:erp_component_bom:remove')")
    @Log(title = "子件BOM", businessType = BusinessType.DELETE)
	@DeleteMapping("/{componentIds}")
    public AjaxResult remove(@PathVariable String[] componentIds)
    {
        return toAjax(erpComponentBomService.deleteErpComponentBomByComponentIds(componentIds));
    }
}
